home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / window / window.sty < prev    next >
Text File  |  1993-11-07  |  9KB  |  207 lines

  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %                                                                              %
  3. %                This is WINDOW.STY               (Elmar Schal\"uck Apr 1991)  %
  4. %                                                                              %
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. \message{This is WINDOW.STY   by Elmar Schalueck    April 1991}
  7. %   These routines and macros are mainly due to Alan Hoenig
  8. %   I myself found them in a lovely book named
  9. %   \TeX: applications, uses, methods (Malcolm Clark, ed.),
  10. %   Horwood, New York 1990
  11. %   Please report errors, suggestions for better versions, etc. to
  12. %   elmar@uni-paderborn.de
  13. %
  14. \newdimen\@totalheight                   % the height of the included box
  15. \newdimen\@wordskip                      % interspace between box and text
  16. \newcount\@numberlines                   % lines corresponding to boxheight
  17. \newdimen\@tempdim                       % vskip box to have middle height
  18. \def\z@pt{0pt}
  19. \newdimen\point@strut                    % help dimension
  20. \newdimen\strut@depth \newdimen\strut@height        % approximate values
  21. \newcount\n@                             % count value for parshaping
  22. \newcount\old@vbadness                   % backup value
  23. \newcount\@top                           % number of full lines
  24. \newcount\@window                        % number of window lines
  25. \newdimen\shave@height                   % backup values
  26. \newdimen\old@split@top@skip \newdimen\old@prevdepth
  27. \newdimen\old@lineskip
  28. \newdimen\@side                          % length of windowtext left and right
  29. \newdimen\left@side \newdimen\right@side % text left and right
  30. \newcount\ratio@left                     % ratio of text left versus right
  31. \newcount\ratio@right
  32. \newcount\ratio@sum
  33. \newcount\ratio@zero                     % instead of a \newif
  34. \newtoks\parshape@spec                   % build the wanted parshape
  35. \newbox\window@parbox                    % the textbox with empty window
  36. \newbox\left@box                         % help box to reassemble line
  37. \newbox\right@box
  38. \newbox\build@par                        % text before reassembling
  39. \newbox\in@window                        % what to put in the window
  40. %
  41. \def\windowbox[toplines: #1][inwindow: #2][ratio: #3 #4]#5\par{%
  42. %  #1 number of lines before the window starts
  43. %  #2 what will be displayed in the window
  44. %  #3 how many parts of the text will be on the left side of the window
  45. %  #4 how many parts of the text will be on the right side of the window
  46. %  #5 the actual text of the window
  47. \old@vbadness=\vbadness \vbadness=10000
  48. \@top=#1
  49. \setbox\in@window\hbox{#2}
  50. \ratio@left=#3
  51. \ratio@right=#4
  52. \ratio@zero=0              % ratio@zero = 0 iff text appears on
  53.                   % both sides of  the window and cutting
  54.                   % and reassembling must be done.
  55. \ifnum\ratio@left=0\ratio@zero=1\fi
  56. \ifnum\ratio@right=0\ratio@zero=1\fi
  57. \calculate@dimens          % collect all values that are necessary
  58. \create@parshapespec       % create the parshape of the text
  59. \setbox\build@par=\vbox{\parshape=\n@ \the\parshape@spec \strut#5}
  60.                   % build the paragraph
  61. \ifnum\ratio@zero=1
  62. \let\window@parbox=\build@par   % the paragraph is ok
  63. \else\open@window\fi            % cut and reassemble
  64. \vskip0.5\@tempdim
  65. \vskip\@top\baselineskip        % place the box inside the window
  66. \noindent
  67. \ifnum\ratio@left=0
  68. \else\hskip\left@side
  69. \hskip\@wordskip
  70. \fi     
  71. \box\in@window                  % jump back to the normal beginning of
  72. \par\nobreak                    % the paragraph. Avoid page breaks
  73. \vskip-0.5\@tempdim
  74. \vskip-\@totalheight
  75. \vskip-\@top\baselineskip
  76. \box\window@parbox              % place the actual text
  77. \vbadness=\old@vbadness                  % restore old settings
  78. \splittopskip=\old@split@top@skip
  79. }
  80. %
  81. \def\open@window{%                      % cut and paste
  82. \old@split@top@skip=\splittopskip \global\splittopskip=0pt
  83. \ifnum\@top=0
  84. \old@prevdepth=\strut@depth\else
  85. \shave@height=\@top\baselineskip
  86. \advance\shave@height by-\strut@depth
  87. \global\setbox\window@parbox=\vsplit\build@par to \shave@height
  88. \old@prevdepth=\dp\window@parbox
  89. \fi
  90. %%          \window@parbox contains the top part of the paragraph
  91. \count10=\@numberlines             % for lines := 1 to @numberlines do
  92. \shave@height=\strut@height
  93. \loop \setbox\left@box=\vsplit\build@par to\shave@height
  94. \setbox\right@box=\vsplit\build@par to\shave@height
  95. %% the left and the right boxes of one line are built
  96. \advance\count10 by-1 \make@line[\left@box,\right@box]
  97. %% now they are reassembled
  98. \ifnum\@top=0                 % if in first line without toplines
  99. \ifnum\count10=\@numberlines
  100. \global\setbox\window@parbox\vbox{\box0}    % initiate window@parbox
  101. \else\addline@to@windowpar                  % else addlines
  102. \fi
  103. \else\addline@to@windowpar
  104. \fi
  105. \ifnum\count10>0 \repeat    % end of window-loop
  106. %%      \window@parbox has the window part too
  107. %%      paste the bottom
  108. \old@lineskip=\lineskip
  109. \global\setbox\window@parbox=\vbox{\prevdepth=\old@prevdepth%
  110. \lineskip=1.5pt                       % This value doesn't seem to fit
  111.                      % for big fontsizes
  112. \unvbox\window@parbox\box\build@par}
  113. \lineskip=\old@lineskip
  114. }
  115. %
  116. \def\calculate@dimens{%
  117. \setbox0\hbox{[}         % to calculate strut@height and strut@depth
  118. \point@strut=\baselineskip
  119. \advance\point@strut by -\ht0
  120. \advance\point@strut by -\dp0
  121. \divide\point@strut by 2
  122. \global\strut@height=\ht0         % just approximate values
  123. \global\strut@depth=\dp0
  124. \global\advance\strut@height by\point@strut
  125. \global\advance\strut@depth by\point@strut
  126. \global\setbox\strutbox=\hbox{\vrule height\strut@height
  127. depth\strut@depth width0pt}                    % adjust the \strutbox
  128. \global\@totalheight=\ht\in@window
  129. \global\advance\@totalheight by\dp\in@window   % the total height of the
  130.                           % included window
  131. \global\@numberlines=\@totalheight
  132. \global\divide\@numberlines by\baselineskip
  133. \global\@tempdim=\baselineskip
  134. \global\multiply\@tempdim by-\@numberlines
  135. \global\advance\@tempdim by\@totalheight
  136. \ifdim\@tempdim>0.3pt%
  137.  \global\advance\@numberlines by 1
  138.  \global\@tempdim=\baselineskip
  139.  \global\multiply\@tempdim by\@numberlines
  140.  \global\advance\@tempdim by-\@totalheight
  141. \fi                                            % number of lines for the window
  142.                           % and additional vskip for window
  143. \global\@wordskip=\fontdimen2\font
  144. \global\@window=\@numberlines
  145. \global\@side=\hsize
  146. \global\advance\@side by-\wd\in@window
  147. \global\advance\@side by-\@wordskip
  148. \ifnum\ratio@zero=0\global\advance\@side by-\@wordskip\fi
  149. \ratio@sum=\ratio@left
  150. \advance\ratio@sum by\ratio@right
  151. \global\left@side=\@side
  152. \global\multiply\left@side by\ratio@left
  153. \global\divide\left@side by\ratio@sum
  154. \global\right@side=\@side
  155. \global\multiply\right@side by\ratio@right
  156. \global\divide\right@side by\ratio@sum         % left side and right side
  157.                           % according to the chosen ratio
  158. }
  159. %
  160. \def\create@parshapespec{%
  161. \global\n@=\@top                               % number of lines for parshape
  162. \global\advance\n@ by\@window
  163. \ifnum\ratio@zero=0\global\advance\n@ by\@window\fi
  164. \global\advance\n@ by1
  165. \global\parshape@spec={}                       % initialize parshape@spec
  166. \count10=\@top                                 % for i := 1 to @top do
  167. \ifnum\@top>0{                                 % add complete lines to shape
  168. \loop \global\parshape@spec=\expandafter{\the\parshape@spec \z@pt\hsize}
  169. \advance\count10 by-1 \ifnum\count10>0 \repeat
  170. }\fi
  171. \count10=\@window                              % for i := 1 to @window do
  172. \loop                                          % add two shorter lines
  173. \ifnum\ratio@zero=0         % both ratio values \neq 0
  174. \global\parshape@spec=\expandafter{\the\parshape@spec
  175. \z@pt\left@side \z@pt\right@side}
  176. \else                       % one ratio value is zero
  177. \ifnum\ratio@left=0
  178. \@side=\hsize\advance\@side by-\right@side     % window at the left side
  179. \global\parshape@spec=\expandafter{\the\parshape@spec
  180. \@side\right@side}\fi
  181. \ifnum\ratio@right=0\global\parshape@spec=\expandafter{\the\parshape@spec
  182. \z@pt\left@side}\fi                            % window at the right side
  183. \fi
  184. \advance\count10 by-1 \ifnum\count10>0 \repeat % end of loop
  185. \global\parshape@spec=\expandafter{\the\parshape@spec \z@pt\hsize}
  186. }                                              % add full line to shape
  187. %
  188. %   unwrap the vertical glue and remove the final glue
  189. \def\unwrap#1#2{\unvbox#1 \setbox#1=\lastbox
  190. \setbox#1=\hbox to#2{\strut\unhbox#1 \unskip}%
  191. }
  192. %
  193. %  make a line of two halfs
  194. \def\make@line[#1,#2]{%
  195. \unwrap\left@box\left@side \unwrap\right@box\right@side
  196. \setbox0=\hbox to\hsize{\box#1\hss\box#2}%
  197. }
  198. %
  199. \def\addline@to@windowpar{%       add the reassembled lines to the output
  200. \global\setbox\window@parbox=\vbox{\prevdepth=\old@prevdepth
  201. \unvbox\window@parbox \box0}%
  202. \old@prevdepth=\dp\window@parbox
  203. }
  204. %
  205. %
  206.  
  207.